/*
 * Qinlan Shen
 * November 8, 2010
 * Pd. 8
 * 
 * Script, based off of Keine's Buretsu/Masakado Crisis.  Difficulty and time limit
 * can be adjusted.
 * 
 */

import java.awt.Image;
import java.util.*;

public class BuretsuCrisis extends RoseScript
{
	private int famLeftX;
	private int famLeftY;
	private int famRightX;
	private int famRightY;
	private int famCenterX;
	private int famCenterY;
	private int famRadius;
	private int[] famAnglesLeft = {180, 300, 60};
	private int[] famAnglesRight = {0, 120, -120};
	private int[] famAnglesCenter = {0, 0, 180, 180};
	
	public BuretsuCrisis(int d, int t)
	{
		super (d, t);
		famRadius = 40;
		famLeftX = 160;
		famLeftY = 120;
		famRightX = 480;
		famRightY = 120;
		famCenterX = 320;
		famCenterY = 360;
	}
	
	public ArrayList<PointItem> run(Rose rose, Character player, int frame, ArrayList<Enemy> enemies, ArrayList<PointItem> points, ArrayList<Image> packets, Image point)
	{

		incrementTime(frame);
		
		rose.moveUsingFrames(320, 120, 120);
		
		if(frame > 120)
		{
			for(int i = 0; i < 3; i++)
			{
				if (difficulty == 9 && frame % 4 == 0 || difficulty > 9 && frame % 8 == 0)
				{
					if (difficulty != 10)
					{
						enemies.add(new PacketSA(packets.get(1), 3, famRightX + famRadius * Math.sin(Math.toRadians(famAnglesRight[i])), famRightY + famRadius * Math.cos(Math.toRadians(famAnglesRight[i])), -2, famAnglesRight[i])); 
						enemies.add(new PacketSA(packets.get(1), 3, famLeftX + famRadius * Math.sin(Math.toRadians(famAnglesLeft[i])), famLeftY + famRadius * Math.cos(Math.toRadians(famAnglesLeft[i])), -2, famAnglesLeft[i]));
					}
					else
					{
						enemies.add(new PacketSA(packets.get(1), 3, famRightX + famRadius * Math.sin(Math.toRadians(famAnglesRight[i])), famRightY + famRadius * Math.cos(Math.toRadians(famAnglesRight[i])), -2, famAnglesRight[i] + 30));
						enemies.add(new PacketSA(packets.get(1), 3, famRightX + famRadius * Math.sin(Math.toRadians(famAnglesRight[i])), famRightY + famRadius * Math.cos(Math.toRadians(famAnglesRight[i])), -2, famAnglesRight[i] - 30)); 
						enemies.add(new PacketSA(packets.get(1), 3, famLeftX + famRadius * Math.sin(Math.toRadians(famAnglesLeft[i])), famLeftY + famRadius * Math.cos(Math.toRadians(famAnglesLeft[i])), -2, famAnglesLeft[i] + 30));
						enemies.add(new PacketSA(packets.get(1), 3, famLeftX + famRadius * Math.sin(Math.toRadians(famAnglesLeft[i])), famLeftY + famRadius * Math.cos(Math.toRadians(famAnglesLeft[i])), -2, famAnglesLeft[i] - 30));
					}
					if (difficulty > 10)
					{
						enemies.add(new PacketSA(packets.get(1), 3, famRightX + famRadius * Math.sin(Math.toRadians(famAnglesRight[i])), famRightY + famRadius * Math.cos(Math.toRadians(famAnglesRight[i])), -2, famAnglesRight[i] + 60));
						enemies.add(new PacketSA(packets.get(1), 3, famRightX + famRadius * Math.sin(Math.toRadians(famAnglesRight[i])), famRightY + famRadius * Math.cos(Math.toRadians(famAnglesRight[i])), -2, famAnglesRight[i] - 60)); 
						enemies.add(new PacketSA(packets.get(1), 3, famLeftX + famRadius * Math.sin(Math.toRadians(famAnglesLeft[i])), famLeftY + famRadius * Math.cos(Math.toRadians(famAnglesLeft[i])), -2, famAnglesLeft[i] + 60));
						enemies.add(new PacketSA(packets.get(1), 3, famLeftX + famRadius * Math.sin(Math.toRadians(famAnglesLeft[i])), famLeftY + famRadius * Math.cos(Math.toRadians(famAnglesLeft[i])), -2, famAnglesLeft[i] - 60));
					}

				}
				famAnglesLeft[i]++;
				famAnglesRight[i]--;
			}

			if (frame % 20 == 0 && difficulty > 9)
			{
				for (int i = 0; i < 4;i++)
				{
					enemies.add(new PacketSA(packets.get(0), 3, famCenterX + famRadius * Math.sin(Math.toRadians(famAnglesCenter[i])), famCenterY + famRadius * Math.cos(Math.toRadians(famAnglesCenter[i])), -2, famAnglesCenter[i] + 30));
					enemies.add(new PacketSA(packets.get(0), 3, famCenterX + famRadius * Math.sin(Math.toRadians(famAnglesCenter[i])), famCenterY + famRadius * Math.cos(Math.toRadians(famAnglesCenter[i])), -2, famAnglesCenter[i] - 30)); 

					if (i % 2 == 0)
						famAnglesCenter[i] += 2;
					else
						famAnglesCenter[i] -= 2;
				}
			}
			
			if (frame % 240 == 0)
				for(int i = 0; i < 45; i++)
					enemies.add(new PacketSA(packets.get(0), 3, rose.getX() + famRadius * Math.sin(Math.toRadians(8 * i)), rose.getY() + famRadius * Math.cos(Math.toRadians(8 * i)), 2, rose.getAngleToPlayer(player)));

			
			if (time < 0)
				points = endScript(point, rose, player, enemies);
		}
		
		return points;

	}
}